package com.rdc.example.view;

import com.rdc.example.bean.dto.ArticleDTO;
import com.rdc.example.bean.dto.ColumnDTO;

import java.util.List;

import static com.rdc.example.view.UtilView.getUserInputString;

/**
 * @author duck
 */
public class ColumnView {

    public static void insertColumn(ColumnDTO columnDTO) {
        String name = getUserInputString("请输入专栏名称： ");
        columnDTO.setName(name);
    }

    public static void showColumn(int i, ColumnDTO dto) {
        System.out.println((i + 1) + "号---------------------------");
        System.out.println("|标题：" + dto.getName() + "\t\t作者：" + dto.getUserName()+"\t\t|创建时间：" + dto.getCreatedAt());
        System.out.println("|");
    }

    public void showColumn(ColumnDTO dto, List<ArticleDTO> list) {
        System.out.println("专栏内容------------------------");
        System.out.println("|标题：" + dto.getName() + "\t\t作者：" + dto.getUserName() + "\t\t|创建时间：" + dto.getCreatedAt());
        System.out.println("|文章-------------------------");
        if (list.isEmpty()) {
            System.out.println("暂无文章，空空如也");
            return;
        }
        for (int i = 0; i < list.size(); i++) {
            String top= list.get(i).getIsTop()?"置顶":" ";
            System.out.println( (i + 1) +"号文章("+top+")------------------");
            System.out.println("|标题："+list.get(i).getTitle()+"\t作者："+list.get(i).getAuthor()+"\t赞数："+list.get(i).getLikes());
            System.out.println("|内容："+list.get(i).getContent());
            System.out.println("|创建时间："+list.get(i).getCreatedAt()+"\t最新评论时间："+list.get(i).getUpdatedAt());
        }
    }

    public static String getInputString(){
        return UtilView.getUserInputString("请输入专栏标题关键词：");
    }




}
